import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Pertutation {
    public static ArrayList<ArrayList<String>> pert(ArrayList<String> list1) {
        ArrayList<ArrayList<String>> answer = new ArrayList<>();
        for (String s1 : list1
        ) {
            ArrayList<String> list2 = (ArrayList<String>) list1.clone();
            list2.remove(s1);
            for (String s2: list2
                 ) {
                ArrayList<String> list3 = (ArrayList<String>) list2.clone();
                list3.remove(s2);
                for (String s3: list3
                     ) {

                    ArrayList<String> list4 = (ArrayList<String>) list3.clone();
                    list4.remove(s3);

                    for (String s4: list4
                         ) {
                        ArrayList<String> list5 = (ArrayList<String>) list4.clone();
                        list5.remove(s4);
                        for (String s5: list5
                             ) {
                            ArrayList<String> tempAnswer = new ArrayList<String>();
                            List l = Arrays.asList(s1, s2, s3, s4, s5);
                            tempAnswer.addAll(l);
                            answer.add(tempAnswer);
                        }
                    }
                }
            }
        }
        return answer;
    }

}
